<template>
  <!-- 团委组织 -->
  <div class="app-container">
    <!-- <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
        <el-tab-pane label="校团委" name="first">
        </el-tab-pane>
        <el-tab-pane label="二级学院团委" name="second"></el-tab-pane>
    </el-tabs> -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学期" prop="schoolYear">
        <el-select v-model="queryParams.schoolYear" placeholder="请选择" style="width: 240px">
          <el-option v-for="option in schoolYearList" :key="option.schoolYearId" :label="option.schoolYearId"
            :value="option.schoolYearId" />
        </el-select>
      </el-form-item>
      <el-form-item label="发起单位" prop="unitName">
        <el-input v-model="queryParams.unitName" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="活动名称" prop="activityName">
        <el-input v-model="queryParams.activityName" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="社团类型" prop="clubType">
        <!-- <el-input v-model="queryParams.clubType" placeholder="请选择" clearable @keyup.enter.native="handleQuery" /> -->
        <el-select v-model="queryParams.clubType" placeholder="请选择">
                <el-option v-for="dict in dict.type.org_club_type" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button type="primary" icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain size="mini" @click="create1"
            v-hasPermi="['organ:groupOrgan:creat']">同步学生</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="primary" plain size="mini" @click="create"
            v-hasPermi="['organ:groupOrgan:creat']">同步活动</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="primary" size="mini" @click="handleAdd" v-hasPermi="['organ:groupOrgan:set']">设置课程表</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
            v-hasPermi="['organ:groupOrgan:export']">外聘老师工资表</el-button>
        </el-col>
      </el-row>
    </el-form>

    <el-table border v-loading="loading" :data="orgList" @selection-change="handleSelectionChange">
      <el-table-column label="活动名称" align="center" prop="orgName" />
      <el-table-column label="发起单位" align="center" prop="unitName" />
      <el-table-column label="指导老师" align="center" prop="teacherName" />
      <el-table-column label="社团类型" align="center" prop="typeName" />
      <el-table-column label="活动时间" align="center" prop="date" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width='400'>
        <template slot-scope="scope">
          <el-button style="padding: 8px;" size="mini" type="primary" v-hasPermi="['organ:groupOrgan:detail']"
            @click="goAct(scope.row)">详情</el-button>
          <el-button style="padding: 8px;margin-right: 8px;" size="mini" type="success"
            @click="code1(scope.row)">二维码</el-button>
          <el-button style="padding: 8px;margin-right: 8px;" size="mini" type="primary"
            v-hasPermi="['organ:groupOrgan:del']" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" @current-change="handleCurrentChange" :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 创建活动 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form1" :rules="rules1" label-width="100px">
        <el-form-item label="活动名称" prop="orgName">
          <el-input v-model="form1.orgName" placeholder="请输入活动名称"></el-input>
        </el-form-item>
        <el-form-item label="指导老师" prop="teacherId">
          <el-select v-model="form1.teacherId" filterable remote reserve-keyword placeholder="请输入关键词"
            :remote-method="remoteMethod2" :loading="searchLoading">
            <el-option v-for="(item, index) in options" :key="index" :label="item.label"
              :value="item.label.substring(0, item.label.lastIndexOf('-'))">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发起单位" prop="unitName">
          <el-select v-model="form1.unitName" placeholder="请选择" clearable @change="changeValue($event)"
            style="width: 240px">
            <el-option v-for="(dict, index) in unitNameList" :key="index" :label="dict.sponsorName" :value="dict">{{
              dict.sponsorName }}</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学生管理员" prop="studentId">
          <el-select v-model="form1.studentId" filterable remote reserve-keyword placeholder="请输入关键词"
            :remote-method="remoteMethod" :loading="searchLoading">
            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="活动时间">
          <el-select v-model="form1.date" placeholder="请选择类型">
            <el-option v-for="dict in timeList" :key="dict.id" :label="dict.date" :value="dict.date"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学分" prop="mark">
          <el-input v-model="form1.mark" placeholder="请输入学分"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!--设置课程表 -->
    <el-dialog :title="title" :visible.sync="updateOpen" width="1300px" append-to-body>
      <div style="display:flex;">
        <div style="border-right:1px solid #ccc;border-bottom:1px solid #ccc;padding-right:20px">
          <el-form :model="first" :rules="rules" label-width="100px">
            <el-row>
              <el-col :span="12">
                <el-form-item label="期数" prop="period">
                  <el-input v-model="first.period" placeholder="请输入" disabled></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="社团类型">
                  <el-input v-model="first.clubType" placeholder="请输入" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="课程数量" prop="num">
                  <el-input v-model="first.num" placeholder="请输入"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-form-item label="开始日期" prop='startDate'>
                <el-date-picker v-model="first.startDate" type="date" value-format="yyyy-MM-dd" placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="上课时间" prop="checkList">
                <el-checkbox-group v-model="first.checkList">
                  <el-checkbox label="周一"></el-checkbox>
                  <el-checkbox label="周二"></el-checkbox>
                  <el-checkbox label="周三"></el-checkbox>
                  <el-checkbox label="周四"></el-checkbox>
                  <el-checkbox label="周五"></el-checkbox>
                  <el-checkbox label="周六"></el-checkbox>
                  <el-checkbox label="周日"></el-checkbox>
                </el-checkbox-group>
              </el-form-item>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="开始时间" prop="startTime">
                  <el-time-select placeholder="起始时间" v-model="first.startTime" :picker-options="{
                    start: '08:30',
                    step: '00:10',
                    end: '18:30'
                  }">
                  </el-time-select>
                  <el-time-select style="margin-left:30px" placeholder="结束时间" v-model="first.endTime" :picker-options="{
                    start: '08:30',
                    step: '00:10',
                    end: '18:30',
                    minTime: first.startTime
                  }">
                  </el-time-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <div style="border-bottom:1px solid #ccc;">
          <el-form :model="two" :rules="rules" label-width="100px">

            <el-row>
              <el-col :span="12">
                <el-form-item label="期数">
                  <el-input v-model="two.period" placeholder="请输入" disabled></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="社团类型">
                  <el-input v-model="two.clubType" placeholder="请输入" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="课程数量" prop="num2">
                  <el-input v-model="two.num" placeholder="请输入"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-form-item label="开始日期" prop="startDate2">
                <el-date-picker v-model="two.startDate" type="date" value-format="yyyy-MM-dd" placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="上课时间" prop="checkList2">
                <el-checkbox-group v-model="two.checkList">
                  <el-checkbox label="周一"></el-checkbox>
                  <el-checkbox label="周二"></el-checkbox>
                  <el-checkbox label="周三"></el-checkbox>
                  <el-checkbox label="周四"></el-checkbox>
                  <el-checkbox label="周五"></el-checkbox>
                  <el-checkbox label="周六"></el-checkbox>
                  <el-checkbox label="周日"></el-checkbox>
                </el-checkbox-group>
              </el-form-item>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="开始时间" prop="startTime2">
                  <el-time-select placeholder="起始时间" v-model="two.startTime" :picker-options="{
                    start: '08:30',
                    step: '00:10',
                    end: '18:30'
                  }">
                  </el-time-select>
                  <el-time-select style="margin-left:30px" placeholder="结束时间" v-model="two.endTime" :picker-options="{
                    start: '08:30',
                    step: '00:10',
                    end: '18:30',
                    minTime: two.startTime
                  }">
                  </el-time-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </div>

      <div style="display:flex">
        <div style="border-right:1px solid #ccc;border-bottom:1px solid #ccc;padding-right:20px">
          <el-form :model="three" :rules="rules" label-width="100px" style="margin-top:50px;">
            <el-row>
              <el-col :span="12">
                <el-form-item label="期数">
                  <el-input v-model="three.period" placeholder="请输入" disabled></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="社团类型">
                  <el-input v-model="three.clubType" placeholder="请输入" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="课程数量" prop="num3">
                  <el-input v-model="three.num" placeholder="请输入"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-form-item label="开始日期" prop="startDate3">
                <el-date-picker v-model="three.startDate" type="date" value-format="yyyy-MM-dd" placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="上课时间" prop="checkList3">
                <el-checkbox-group v-model="three.checkList">
                  <el-checkbox label="周一"></el-checkbox>
                  <el-checkbox label="周二"></el-checkbox>
                  <el-checkbox label="周三"></el-checkbox>
                  <el-checkbox label="周四"></el-checkbox>
                  <el-checkbox label="周五"></el-checkbox>
                  <el-checkbox label="周六"></el-checkbox>
                  <el-checkbox label="周日"></el-checkbox>
                </el-checkbox-group>
              </el-form-item>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="开始时间" prop="startTime3">
                  <el-time-select placeholder="起始时间" v-model="three.startTime" :picker-options="{
                    start: '08:30',
                    step: '00:10',
                    end: '18:30'
                  }">
                  </el-time-select>
                  <el-time-select style="margin-left:30px" placeholder="结束时间" v-model="three.endTime" :picker-options="{
                    start: '08:30',
                    step: '00:10',
                    end: '18:30',
                    minTime: three.startTime
                  }">
                  </el-time-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <div style="border-bottom:1px solid #ccc;">
          <el-form :model="fore" :rules="rules" label-width="100px" style="margin-top:50px;">
            <el-row>
              <el-col :span="12">
                <el-form-item label="期数">
                  <el-input v-model="fore.period" placeholder="请输入" disabled></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="社团类型">
                  <el-input v-model="fore.clubType" placeholder="请输入" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="课程数量" prop="num4">
                  <el-input v-model="fore.num" placeholder="请输入"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-form-item label="开始日期" prop="startDate4">
                <el-date-picker v-model="fore.startDate" type="date" value-format="yyyy-MM-dd" placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="上课时间" prop="checkList4">
                <el-checkbox-group v-model="fore.checkList">
                  <el-checkbox label="周一"></el-checkbox>
                  <el-checkbox label="周二"></el-checkbox>
                  <el-checkbox label="周三"></el-checkbox>
                  <el-checkbox label="周四"></el-checkbox>
                  <el-checkbox label="周五"></el-checkbox>
                  <el-checkbox label="周六"></el-checkbox>
                  <el-checkbox label="周日"></el-checkbox>
                </el-checkbox-group>
              </el-form-item>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="开始时间" prop="startTime4">
                  <el-time-select placeholder="起始时间" v-model="fore.startTime" :picker-options="{
                    start: '08:30',
                    step: '00:10',
                    end: '18:30'
                  }">
                  </el-time-select>
                  <el-time-select style="margin-left:30px" placeholder="结束时间" v-model="fore.endTime" :picker-options="{
                    start: '08:30',
                    step: '00:10',
                    end: '18:30',
                    minTime: fore.startTime
                  }">
                  </el-time-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </div>

      <div style="display:flex">
        <div style="border-right:1px solid #ccc;padding-right:20px">
          <el-form :model="five" :rules="rules" label-width="100px" style="margin-top:50px;">
            <el-row>
              <el-col :span="12">
                <el-form-item label="期数">
                  <el-input v-model="five.period" placeholder="请输入" disabled></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="社团类型">
                  <el-input v-model="five.clubType" placeholder="请输入" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="课程数量" prop="num5">
                  <el-input v-model="five.num" placeholder="请输入"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-form-item label="开始日期" prop="startDate5">
                <el-date-picker v-model="five.startDate" type="date" value-format="yyyy-MM-dd" placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="上课时间" prop="checkList5">
                <el-checkbox-group v-model="five.checkList">
                  <el-checkbox label="周一"></el-checkbox>
                  <el-checkbox label="周二"></el-checkbox>
                  <el-checkbox label="周三"></el-checkbox>
                  <el-checkbox label="周四"></el-checkbox>
                  <el-checkbox label="周五"></el-checkbox>
                  <el-checkbox label="周六"></el-checkbox>
                  <el-checkbox label="周日"></el-checkbox>
                </el-checkbox-group>
              </el-form-item>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="开始时间" prop="startTime5">
                  <el-time-select placeholder="起始时间" v-model="five.startTime" :picker-options="{
                    start: '08:30',
                    step: '00:10',
                    end: '18:30'
                  }">
                  </el-time-select>
                  <el-time-select style="margin-left:30px" placeholder="结束时间" v-model="five.endTime" :picker-options="{
                    start: '08:30',
                    step: '00:10',
                    end: '18:30',
                    minTime: five.startTime
                  }">
                  </el-time-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <el-form :model="six" :rules="rules" label-width="100px" style="margin-top:50px;">
          <el-row>
            <el-col :span="12">
              <el-form-item label="期数">
                <el-input v-model="six.period" placeholder="请输入" disabled></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="社团类型">
                <el-input v-model="six.clubType" placeholder="请输入" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="课程数量" prop="num6">
                <el-input v-model="six.num" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-form-item label="开始日期" prop="startDate6">
              <el-date-picker v-model="six.startDate" type="date" value-format="yyyy-MM-dd" placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="上课时间" prop="checkList6">
              <el-checkbox-group v-model="six.checkList">
                <el-checkbox label="周一"></el-checkbox>
                <el-checkbox label="周二"></el-checkbox>
                <el-checkbox label="周三"></el-checkbox>
                <el-checkbox label="周四"></el-checkbox>
                <el-checkbox label="周五"></el-checkbox>
                <el-checkbox label="周六"></el-checkbox>
                <el-checkbox label="周日"></el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="开始时间" prop="startTime6">
                <el-time-select placeholder="起始时间" v-model="six.startTime" :picker-options="{
                  start: '08:30',
                  step: '00:10',
                  end: '18:30'
                }">
                </el-time-select>
                <el-time-select style="margin-left:30px" placeholder="结束时间" v-model="six.endTime" :picker-options="{
                  start: '08:30',
                  step: '00:10',
                  end: '18:30',
                  minTime: six.startTime
                }">
                </el-time-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormUpdateDetail">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 二维码对话框 -->
    <el-dialog :title="title" :visible.sync="QRCode" width="380px" append-to-body>
      <el-card>
        <el-image id="erCode" v-if="QRCodeImage" style="width: 300px; height: 300px" :src="QRCodeImage"
          :preview-src-list="[QRCodeImage]" fit="cover">
        </el-image>
        <el-button type="primary" @click="openUrl(QRCodeImage, title)">点击下载</el-button>
      </el-card>
    </el-dialog>

    <!-- 外聘老师选择月份 -->
    <el-dialog title="外聘老师工资表导出" :visible.sync="exportOpen" width="380px" append-to-body>
      <el-form ref="form" :model="form">
        <el-form-item label="月份" prop="title">
          <el-date-picker v-model="exportMonth" value-format="yyyyMMdd" type="month" placeholder="选择月份">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="exportSubmit">导 出</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="title" :visible.sync="actOpen" width="700px" append-to-body>
      <el-form ref="form" :model="formModel" :rules="rules" label-width="100px">
                <el-col :span="12">
                  <el-form-item label="学期" prop="schoolYear">
                    <el-select
                      v-model="formModel.schoolYear"
                      placeholder="请选择"
                      clearable
                      @change="changeTime($event)"
                    >
                      <el-option
                        v-for="option in schoolYearList"
                        :key="option.schoolYearId"
                        :label="option.schoolYearId"
                        :value="option.schoolYearId"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="期" prop="period">
                    <el-select
                      v-model="formModel.period"
                      placeholder="请选择"
                      clearable
                    >
                      <el-option
                        v-for="option in timeList"
                        :key="option.dictCode"
                        :label="option.dictValue"
                        :value="option.dictValue"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="sure">确认同步</el-button>
        <el-button @click="cancel">取消同步</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listOrg,
  getOrg,
  delOrg,
  addOrg,
  updateOrg,
  getstudentmanager,
  getTeacherManager,
  setstudentmanager,
  setteachermanager,
  editDefaultSchoolYear,
  upClass,
  showQrCode,
  downloadImgs,
  timeList,
  actAct,
  actAct1,
  addOrgList,
  addClass,
  getClass
} from "@/api/organ/groupOrgan";
import { listSponsor } from "@/api/system/sponsor";
import {
  getTime
} from '@/api/organ/studentOrgan';
import { mapGetters } from 'vuex';
import { MessageBox, Message } from 'element-ui';
import { GetYearList } from '@/api/organ/organ';
export default {
  name: "GroupOrgan",
  computed: {
    ...mapGetters(['roles', 'name']),
  },
  dicts: ['sys_normal_disable', 'orgStatus', 'org_club_type', 'org_club_period'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      curSchoolYear: '',
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      formModel:{},
      // 总条数
      total: 0,
      first: { period: 'A', clubType: '普修社团', checkList: [] },
      two: { period: 'B', clubType: '普修社团', checkList: [] },
      three: { period: 'C', clubType: '普修社团', checkList: [] },
      fore: { period: 'D', clubType: '普修社团', checkList: [] },
      five: { period: 'A', clubType: '精修社团', checkList: [] },
      six: { period: 'C', clubType: '精修社团', checkList: [] },
      // 组织信息表格数据
      orgList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 外聘老师选择月份弹框
      exportOpen: false,
      exportMonth:null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        schoolYear: null,
        clubType:null,
      },
      // 表单参数
      form: {},
      form1: {},
      // 表单校验
      rules: {
        date: [
          { required: true, message: '活动时间不能为空', trigger: 'blur' }
        ],
        num: [
          { required: true, message: '课程数量不能为空', trigger: 'blur' }
        ],
        checkList: [
          { required: true, message: '上课时间不能为空', trigger: 'blur' }
        ],
        startDate: [
          { required: true, message: '开始日期不能为空', trigger: 'blur' }
        ],
        startTime: [
          { required: true, message: '时间不能为空', trigger: 'blur' }
        ],
        schoolYear: [
          { required: true, message: '日期不能为空', trigger: 'blur' }
        ],
        period: [
          { required: true, message: '期数不能为空', trigger: 'blur' }
        ],
      },
      rules2: {
        num: [
          { required: true, message: '课程数量不能为空', trigger: 'blur' }
        ],
        checkList: [
          { required: true, message: '上课时间不能为空', trigger: 'blur' }
        ],
        startDate: [
          { required: true, message: '开始日期不能为空', trigger: 'blur' }
        ],
        startTime: [
          { required: true, message: '时间不能为空', trigger: 'blur' }
        ],
      },
      rules3: {
        num: [
          { required: true, message: '课程数量不能为空', trigger: 'blur' }
        ],
        checkList: [
          { required: true, message: '上课时间不能为空', trigger: 'blur' }
        ],
        startDate: [
          { required: true, message: '开始日期不能为空', trigger: 'blur' }
        ],
        startTime: [
          { required: true, message: '时间不能为空', trigger: 'blur' }
        ],
      },
      rules4: {
        num: [
          { required: true, message: '课程数量不能为空', trigger: 'blur' }
        ],
        checkList: [
          { required: true, message: '上课时间不能为空', trigger: 'blur' }
        ],
        startDate: [
          { required: true, message: '开始日期不能为空', trigger: 'blur' }
        ],
        startTime: [
          { required: true, message: '时间不能为空', trigger: 'blur' }
        ],
      },
      rules5: {
        num: [
          { required: true, message: '课程数量不能为空', trigger: 'blur' }
        ],
        checkList: [
          { required: true, message: '上课时间不能为空', trigger: 'blur' }
        ],
        startDate: [
          { required: true, message: '开始日期不能为空', trigger: 'blur' }
        ],
        startTime: [
          { required: true, message: '时间不能为空', trigger: 'blur' }
        ],
      },
      rules6: {
        num: [
          { required: true, message: '课程数量不能为空', trigger: 'blur' }
        ],
        checkList: [
          { required: true, message: '上课时间不能为空', trigger: 'blur' }
        ],
        startDate: [
          { required: true, message: '开始日期不能为空', trigger: 'blur' }
        ],
        startTime: [
          { required: true, message: '时间不能为空', trigger: 'blur' }
        ],
      },
      rules1: {
        orgName: [
          { required: true, message: '活动名称不能为空', trigger: 'blur' }
        ],
        studentId: [
          { required: true, message: '学生管理员不能为空', trigger: 'blur' }
        ],
        teacherId: [
          { required: true, message: '指导老师不能为空', trigger: 'blur' }
        ],
        unitName: [
          { required: true, message: '发起单位不能为空', trigger: 'blur' }
        ],
        date: [
          { required: true, message: '活动时间不能为空', trigger: 'blur' }
        ],
        mark: [
          { required: true, message: '学分不能为空', trigger: 'blur' }
        ],
      },
      options: [],
      value: [],
      list: [],
      searchLoading: false,
      unitNameList: [],
      timeList: [],
      orgForm: {},
      activeName: 'first',
      teacherOpen: false,
      updateOpen: false,
      schoolYearList: [],
      QRCodeImage: [],
      QRCode: false,
      actOpen: false
    };
  },
  created() {
    GetYearList().then(response => {
      console.log(response, 'Years');
      this.schoolYearList = response.rows;
      for (let i = 0; i < response.total; i++) {
        if (response.rows[i].defaultValue == "1") {
          console.log(response.rows[i], "year")
          this.queryParams.schoolYear = response.rows[i].schoolYearId;
        }
      }
    });
    /** 学院下拉框 */
    listSponsor().then(response => {
      this.unitNameList = response.rows;
    });

    this.getList();

  },
  methods: {
    // getYear() {

    // },
    changeTime(e){
      console.log(e,'222222222222222222222222222222222222222');
      getTime(e).then(res=>{
        console.log(res);
        this.timeList = res.data
      })
    },
    formatTime(row, column) {
      let data = row[column.property]
      let dtime = new Date(data)
      const year = dtime.getFullYear()
      let month = dtime.getMonth() + 1
      if (month < 10) {
        month = '0' + month
      }
      let day = dtime.getDate()
      if (day < 10) {
        day = '0' + day
      }
      return year + '-' + month + '-' + day

    },
    // 去活动详情
    goAct(row) {
      console.log(row);
      this.$router.push({
        path: '/organ/groupOrgan-data/index/' + row.id
      })
    },
    // 二维码
    code1(row) {
      this.title = row.orgName
      showQrCode(row.id).then(res => {
        console.log(res);
        if (res.code == 200) {
          // Message({
          //   message: '二维码已生成',
          //   type: 'success',
          // });
          this.QRCodeImage = res.msg;

          this.QRCode = true;
        }
      });

    },
    // 下载二维码
    openUrl(fileName, title) {
      const dataurl = document.getElementById('erCode').src//选择图片id
      // this.downloadBase64(dataurl, this.erCode_name)
      const a = document.createElement('a')
      a.href = dataurl
      a.download = title + '.jpg';
      document.body.appendChild(a)
      a.click()
      document.body.removeChild(a)
    },
    // 指导单位赋值
    changeValue(event) {
      console.log(event, "valllll")
      this.form1.unitCode = event.sponsorCode
      this.form1.unitName = event.sponsorName
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    setSchoolYear(command) {
      console.log(command);
      var param = {
        schoolYearId: command,
        defaultValue: 1,
      };
      this.$modal
        .confirm('是否确认设置"' + command + '"为当前学期？')
        .then(function () {
          return editDefaultSchoolYear(param);
        })
        .then(() => {
          this.getYear();
          this.getList();
          this.$modal.msgSuccess('设置成功');
        })
        .catch(() => { });
      // this.queryParams.schoolYear = command;
      // this.download('committee/org/export2', {
      //   ...this.queryParams
      // }, `org_${new Date().getTime()}.xlsx`)
    },
    /** 查询组织信息列表 */
    getList() {
      this.loading = true;
      // this.orgList = [];
      // this.total = 0;
      // var queryParams2 =JSON.parse(JSON.stringify(this.queryParams));
      // queryParams2.type = 6;
      // listOrg(queryParams2).then(response => {
      listOrg(this.queryParams).then(response => {
        this.orgList = response.rows;
        this.total = response.total;
      });
      // });
      this.loading = false;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.actOpen = false
      this.exportOpen = false;
      this.teacherOpen = false;
      this.updateOpen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        date: null,
        num: null,
        clubType: null
      };
      this.form1 = {}
      // this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.unitName = ''
      this.queryParams.activityName = ''
      this.queryParams.clubType = ''

      // this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.orgId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.updateOpen = true;
      this.title = "设置课程表";
      getClass().then(res => {
        console.log(res);
        this.first = res.data[0]
        this.two = res.data[1]
        this.three = res.data[2]
        this.fore = res.data[3]
        this.five = res.data[4]
        this.six = res.data[5]
      })
    },
    // 去创建活动
    create1() {
      //   this.open = true
      //   timeList().then(res=>{
      //   console.log(res);
      //   this.timeList = res.data
      // })
      this.actOpen = true
      // MessageBox.confirm(`是否确认同步学生数据`, '提示', {
      //   confirmButtonText: '确定',
      //   cancelButtonText: '取消',
      //   type: 'warning',
      // }).then(() => {
      //   actAct1().then(res => {
      //     if (res.code === 200) {
      //       this.$message.success(res.msg)
      //       this.getList()
      //     } else {
      //       this.$message.error(res.msg)
      //     }
      //   })

      // });
    },
    sure(){
      actAct1(this.formModel).then(res => {
          if (res.code === 200) {
            this.$message.success(res.msg)
            this.actOpen = false
            this.getList()
          } else {
            this.actOpen = false
            this.$message.error(res.msg)
          }
        })
    },
    create() {
      //   this.open = true
      //   timeList().then(res=>{
      //   console.log(res);
      //   this.timeList = res.data
      // })
      MessageBox.confirm(`是否确认同步活动数据`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        actAct().then(res => {
          if (res.code === 200) {
            this.$message.success(res.msg)
            this.getList()
          } else {
            this.$message.error(res.msg)
          }
        })

      });
    },
    /** 提交按钮 */
    submitForm() {
      // console.log(this.form1);
      addOrgList(this.form1).then(res => {
        if (res.code == 200) {
          this.$modal.msgSuccess("添加成功");
          this.open = false;
          this.reset()
          this.getList();
        }
      })
    },

    // 添加课程表
    submitFormUpdateDetail() {
      console.log(this.first);
      let arr = []
      arr.push(JSON.parse(JSON.stringify(this.first)))
      arr.push(JSON.parse(JSON.stringify(this.two)))
      arr.push(JSON.parse(JSON.stringify(this.three)))
      arr.push(JSON.parse(JSON.stringify(this.fore)))
      arr.push(JSON.parse(JSON.stringify(this.five)))
      arr.push(JSON.parse(JSON.stringify(this.six)))
      console.log(arr);
      // this.$messmge.success('')
      // this.updateOpen = false
      addClass(arr).then(res => {
        console.log(res);
        this.updateOpen = false
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal.confirm('是否确认删除活动名称为"' + row.orgName + '"的数据项？').then(function () {
        return delOrg(id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.exportOpen = true;
      // this.download('/committee/orgCourse/exportSalaryTable', {}, `Salary_${new Date().getTime()}.xlsx`)
    },
    exportSubmit(){
      console.log(this.exportMonth,"month")
      this.download('/committee/orgCourse/exportSalaryTable', {month:this.exportMonth}, `Salary_${new Date().getTime()}.xlsx`)
      this.exportOpen = false;
    },
    // 判断是否能设置学生
    canWrite(row) {
      console.log(row);
      var isCanWrite = false;
      if (this.roles) {
        console.log(this.roles, 'roles');
        for (let i = 0; i < this.roles.length; i++) {
          if (
            this.roles[i] == 'student-school' ||
            this.roles[i] == 'common' ||
            this.roles[i] == 'admin'
          ) {
            isCanWrite = true;
            break;
          }
          if (this.name == row.teacherId) {
            isCanWrite = true;
            break;
          }
        }
      }
      console.log(isCanWrite, 'isCanWrite');
      return isCanWrite;
    },
    /** 查询学生管理员 */
    remoteMethod(query) {
      if (query !== '') {
        this.loading = true;
        getstudentmanager(query).then(response => {
          this.loading = false;
          this.options = response.rows.filter(item => {
            return item.label.toLowerCase()
              .indexOf(query.toLowerCase()) > -1;
          });
        });
      } else {
        this.options = [];
      }
    },
    /** 查询教师管理员 */
    remoteMethod2(query) {
      if (query !== '') {
        this.loading = true;
        getTeacherManager(query).then(response => {
          this.loading = false;
          this.options = response.rows.filter(item => {
            return item.label.toLowerCase()
              .indexOf(query.toLowerCase()) > -1;
          });
        });
      } else {
        this.options = [];
      }
    },
    /** 导出
     */
    handleCommand(command) {
      this.queryParams.schoolYear = command;
      this.download('committee/org/export2', {
        ...this.queryParams
      }, `org_${new Date().getTime()}.xlsx`)
    },
    /** 切换标签卡 */
    handleClick(tab, event) {
      if (tab.index == '0') {

        this.getList();
      } else {
        this.getList();
      }
    }
  }
};
</script>
<style scoped></style>